<?php
namespace Index\Controller;
use Think\Controller;
use Think\Page;
class QuestionController extends Controller {
    public function index(){
        $id = I("get.id");
        $m = M();
        $sql = "select a.*,b.* from wenti a join user b on a.sid = b.id where a.id = {$id}";
        $ret = $m->query($sql);
        $ret = $ret[0];
        $cs = $ret['cs'];
        $cs = intval($cs);
        $cs++;
        $sql = "update wenti set cs = {$cs} where id = {$id}";
        $m->execute($sql);
        var_dump($cs);
        $sql = "select a.*,b.* from huifu a join user b on a.uid = b.id where a.wid = {$id}";
        $rt = $m->query($sql);
        $sql = "select user_name,avatarulr from user where id = {$_SESSION['id']}";
        $mret = $m->query($sql);
//        var_dump($mret);
        $mret = $mret[0];
        $this->assign('ret', $ret);
        $this->assign('rt', $rt);
        $this->assign('mret', $mret);
        $this->assign('id', $id);
        $this->display("index");
    }
    public function huikui(){
        $wid =  I("post.sid");
        $text = I('post.text');
        $uid = $_SESSION['id'];
        $tim = time();
        $sql = "insert into `huifu` (uid,wid,text,tim) values({$uid},{$wid},'{$text}','{$tim}')";
        $m = M();
        if($m->execute($sql)){
            $sql = "select hfs from wenti where id = '{$wid}'";
            $hfs = $m->query($sql);
            $hfs = $hfs[0]['hfs'];
            $hfs++;
            $sql = "update wenti set hfs = {$hfs} where id = {$wid}";
            if($m->execute($sql)) {
                $this->error("回复成功", U('/index/question/index/') . "/id/{$wid}");
            }
        };
    }
    public function guanzhu(){
        $m = M();
        $id = I("get.id");
        $sql = "select gzs from wenti where id = '{$id}'";
        $gzs = $m->query($sql);
        $gzs = $gzs[0]['gzs'];
        $gzs++;
        $sql = "update wenti set gzs = {$gzs} where id = {$id}";
        if($m->execute($sql)) {
            echo $gzs;
        }else{
            echo "NaN";
        }

    }
}